package com.zzptc.tkfate;

import android.content.Context;
import android.graphics.Color;
import android.net.Uri;
import android.os.Bundle;

import androidx.fragment.app.Fragment;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.github.mikephil.charting.charts.BarChart;
import com.github.mikephil.charting.components.XAxis;
import com.github.mikephil.charting.data.BarData;
import com.github.mikephil.charting.data.BarDataSet;
import com.github.mikephil.charting.data.BarEntry;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;


public class SecondFragment extends Fragment {


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_second, container, false);

        BarChart bar = view.findViewById(R.id.barChart);

        List<BarEntry> barList = new ArrayList<>();
        List<BarEntry> mBarList = new ArrayList<>();

        for (int i = 0; i < 5; i++) {
            barList.add(new BarEntry(i,new Random().nextInt(20)));
            mBarList.add(new BarEntry(i,new Random().nextInt(25)));

        }

        BarDataSet barDataSet=new BarDataSet(barList,"大");
        barDataSet.setColor(Color.BLUE);
        BarData barData=new BarData(barDataSet);
        BarDataSet barDataSet1 = new BarDataSet(mBarList,"小");
        barDataSet1.setColor(Color.BLACK);
        barData.addDataSet(barDataSet1);
        bar.setData(barData);


        bar.getXAxis().setPosition(XAxis.XAxisPosition.BOTTOM);

        bar.getAxisRight().setEnabled(false);
        barData.setBarWidth(0.2f);
        bar.groupBars(1,0.6f,0);

        bar.getXAxis().setAxisMaximum(10);
        bar.getXAxis().setAxisMinimum(1);
        bar.getXAxis().setLabelCount(10,false);
        bar.getXAxis().setCenterAxisLabels(true);
        // Inflate the layout for this fragment
        return view;

    }

}
